import 'package:baselib/utils/image_util.dart';
import 'package:baselib/utils/keyboard_util.dart';
import 'package:baselib/utils/px_base_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'comm_button.dart';
import 'comm_form_input_widget.dart';
import 'comm_textfield.dart';

class PageWidgetManager{
  static Widget buildPage({required BuildContext context,Key? key,
    Color? backgroundColor,bool? resizeToAvoidBottomInset,
    PreferredSizeWidget? appBar,Widget? body,Widget? bottomNavigationBar,
    Widget? floatingActionButton,FloatingActionButtonLocation? floatingActionButtonLocation,
    Widget? endDrawer
  }){
    return KeyBoardUtil.KeyBoardOnTouchDownWidget(
        context,
        child: Scaffold(
          key: key,
          appBar: appBar,
          resizeToAvoidBottomInset: resizeToAvoidBottomInset,
          floatingActionButton: floatingActionButton,
          floatingActionButtonLocation: floatingActionButtonLocation,
          bottomNavigationBar: bottomNavigationBar,
          backgroundColor: backgroundColor,
          endDrawer: endDrawer,
          body: body,
        )
    );
  }

  //备注
  static buidVerticalFormInputUi(
      {
        Key? key,
        String? defaultCont,
        String? hitText,
        bool? isShowTopTitle,
        bool? isNecessary,
        bool? readOnly,
        String? title,
        double? formInputMarginBottom,
        EdgeInsetsGeometry? margin,
        List<TextInputFormatter>? inputFormatters,
        Color? bgColor,
        Alignment? outAlignment,
        TextAlign? inputTextAlign,
        double? hintFontSize,
        double? fontSize,
        Color? hintFontColor,
        Color? fontColor,
        EdgeInsetsGeometry? titleMargin,
        TextStyle? titleStyle,
        TextInputType? keyboardType,
        double? inputHeight,
        int? maxLength,
        int? maxLines,
        int? minLines,
        BorderRadiusGeometry? borderRadius,
        Color? borderColor,
        required Function inputChanged,
      }) {
    return Container(
      margin: margin ?? EdgeInsets.only(),
      padding: EdgeInsets.only(
        left: px_12.w,
        right: px_12.w,
        top: px_10.h,
        bottom: px_10.h,
      ),
      width: pxScreenWidth(),
      decoration: BoxDecoration(
          color: bgColor??color_white,
          borderRadius: borderRadius
      ),
      child: CommFormInputWidget(
        key: key,
        title: title??string_remark,
        isNecessary: isNecessary??false,
        inputFormatters: inputFormatters,
        outAlignment:outAlignment,
        inputTextAlign:inputTextAlign,
        fontSize: fontSize,
        fontColor: fontColor,
        height: inputHeight,
        maxLines: maxLines,
        minLines: minLines,
        maxLength: maxLength,
        hintFontSize: hintFontSize,
        hintFontColor: hintFontColor,
        titleMargin: titleMargin,
        titleStyle: titleStyle,
        keyboardType: keyboardType,
        borderColor: borderColor,
        hintText: hitText ?? (string_please_input+string_remark),
        readOnly: readOnly??false,
        defaultCont: defaultCont ?? '',
        onChanged: (value){
          if(inputChanged!=null)inputChanged!(value,);
        },
      ),
    );
  }

 static buildFouncItemUi(BuildContext context,{
    BorderRadius? borderRadius,String? iconPath,Color? iconColor,double? iconWidth,bool? isOrigin,
    String? title,String? cont,double? itemHeight,String? placeHolder,
    TextStyle? titleTextStyle,TextStyle? contTextStyle,bool? showLeftArr,bool? showRightArr,
    Function? onTap
  }) {
    return CommButton(
      onTap: (onTap==null)?((){}):(()=>onTap!()),
      borderRadius: borderRadius,
      child: Container(
        width: MediaQuery.sizeOf(context).width,
        height: itemHeight??px_56.h,
        padding: EdgeInsets.only(
          left: px_12.w,
          right: px_12.w,
        ),
        child: Row(
          children: [
            !(showLeftArr??false)?SizedBox(width: px_0,):
            ImageUtil.loadAssetImage(
                iconPath??'',
                isOrigin: isOrigin,
                width: iconWidth??px_23.w,
                color: iconColor??color_main
            ),
            !(showLeftArr??false)?SizedBox(width: px_0,):
            SizedBox(width: px_12.w,),
            Expanded(child: Text(
              title??'',
              style: titleTextStyle??TextStyle(
                  color: color_666666,
                  fontSize: px_16.sp
              ),
            )),
            (cont??'').isEmpty?
            Text(
              placeHolder??'',
              style: contTextStyle??TextStyle(
                  color: color_999999,
                  fontSize: px_16.sp
              ),
            ):
            Text(
              cont??'',
              style: contTextStyle??TextStyle(
                  color: color_333333,
                  fontSize: px_16.sp
              ),
            ),
            !(showRightArr??true)?SizedBox(width: px_0,):
            Icon(
              Icons.arrow_forward_ios,
              color: color_999999,
              size: px_16.sp,
            )
          ],
        ),
      ),
    );
  }

  static Widget bar({
    double? width,double? height,Color? color,BorderRadiusGeometry? borderRadius,
    EdgeInsets? outMargin,EdgeInsets? outPadding,Color? outColor,double? outWidth,
    EdgeInsets? margin,EdgeInsets? padding,
  }){
    return Container(
      width: outWidth??pxScreenWidth(),
      padding: outPadding,
      margin: outMargin,
      color: outColor,
      child: Container(
        padding: padding,
        margin: margin,
        width: width??pxScreenWidth(),
        height: height??px_1.h,
        decoration: BoxDecoration(
            color: color??color_f2f2f2,
            borderRadius: borderRadius
        ),
      ),
    );
  }

  static Widget buildCommVerticalSingleInputUi({
    String? title,
    Color? titleColor,
    double? titleFontSize,
    TextStyle? titleTextStyle,
    EdgeInsetsGeometry? margin,
    BorderRadiusGeometry? borderRadius,
    Color? bgColor,
    bool? isNecessary,
    String? defaultCont,
    bool? isShowLable,
    String? hintTxt,
    Color? cursorColor,
    TextInputType? keyboardType,
    String? lableText,
    TextStyle? hintStyle,
    TextStyle? labelStyle,
    TextStyle? style,
    Widget? prefixIcon,
    bool? isShowPrefixIcon,
    EdgeInsets? contentPadding,
    int? maxLength,
    List<TextInputFormatter>? inputFormatters,
    required Function onInputChange
  }){
    return Container(
      margin: margin ?? EdgeInsets.only(),
      padding: EdgeInsets.only(
        top: px_10.h,
        bottom: px_10.h,
      ),
      width: pxScreenWidth(),
      decoration: BoxDecoration(
          color: bgColor??color_white,
          borderRadius: borderRadius
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //title
          Container(
            padding: EdgeInsets.only(
              left: px_12.w,
              bottom: px_8.h,
            ),
            child: Row(
              children: [
                !(isNecessary??false)?SizedBox(width: px_0.w,):
                Text(
                  '*',
                  style: TextStyle(
                      color: color_red,
                      fontSize: titleFontSize??(px_16.sp)
                  ),
                ),
                Expanded(child: Text(
                  title??'',
                  style: titleTextStyle??TextStyle(
                      color: titleColor??color_666666,
                      fontSize: titleFontSize??(px_16.sp)
                  ),
                ))
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.only(
              left: px_12.w,
              right: px_12.w,
            ),
            child: CommTextFieldWidget(
              cursorColor: cursorColor,
              keyboardType: keyboardType,
              defaultCont: defaultCont,
              hintStyle: hintStyle,
              labelStyle: labelStyle,
              style: style,
              lableText: lableText,
              isShowLable: isShowLable??false,
              hintTxt: hintTxt??string_please_input,
              prefixIcon: prefixIcon,
              isShowPrefixIcon: isShowPrefixIcon??false,
              maxLength: maxLength,
              contentPadding: contentPadding??EdgeInsets.only(
                left: px_10.w,
                right: px_10.w,
              ),
              inputFormatters: inputFormatters,
              onChanged: (value)=>onInputChange(value),
            ),
          )
        ],
      ),
    );
  }

}